/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-08-31
 * Time: 10:52
 */
class Solution2 {
    public boolean CheckPermutation(String s1, String s2) {
        int[] hash = new int[26];

        int n = s1.length(), m = s2.length();

        if(n != m) {
            return false;
        }
        // 将s1映射到hash1中去
        for(int i = 0; i < n; i++) {
            hash[s1.charAt(i)-'a']++;
        }
        // 遍历第二个字符串，判断是否可以重排
        for(int j = 0; j < m; j++) {
            hash[s2.charAt(j)-'a']--;
            if(hash[s2.charAt(j)-'a'] < 0) {
                return false;
            }
        }
        return true;
    }
}
